home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / UNGETCH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  602 b   |  18 lines

  1. /* ungetch.c --- p 528 */
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <ctype.h>               /* For the macro isdigit()  */
  5. main()
  6. {
  7.     int intval = 0, c;
  8.     char buff[81];
  9.                     /* Ask user to type in an integer */
  10.     printf("Enter an integer followed by some other characters:");
  11.     while ( (c= getche()) != EOF && isdigit(c) )
  12.         intval = 10*intval + c - 48; /* 0 is ASCII 48 */
  13.             /* Push back the first non-digit read from stdin */
  14.     if (c != EOF) ungetch(c);
  15.                         /* Print message to user */
  16.     printf("\nInteger you entered = %d.\n "
  17.         "First non-integer encountered: %c\n", intval, getch());
  18. }